package com.yoomiito.app.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;

import com.yoomiito.app.R;
import com.yoomiito.app.utils.DensityUtil;

public class RoundImageView_24 extends BaseImageView {
    private static final int DEFAULT_SIZE = 4;
    private static int radius;

    public RoundImageView_24(Context context) {
        this(context, null);
    }

    public RoundImageView_24(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RoundImageView_24(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RoundImageView);
        radius = (int) ta.getDimension(R.styleable.RoundImageView_iv_radius, DEFAULT_SIZE);
        ta.recycle();
    }

    public static Bitmap getBitmap(int width, int height) {
        Bitmap bitmap = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.BLACK);
        canvas.drawOval(new RectF(0.0f, 0.0f, width, height), paint);
        RectF oval3 = new RectF(0, 0, width, height);// 设置个新的长方形
        canvas.drawRoundRect(oval3, DensityUtil.dp2px(24), DensityUtil.dp2px(24), paint);//第二个参数是x半径，第三个参数是y半径

        return bitmap;
    }

    @Override
    public Bitmap getBitmap() {
/*
        int width = getWidth();
        int height = getHeight();

        Bitmap bitmap = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.BLACK);
        canvas.drawOval(new RectF(0.0f, 0.0f, width, height), paint);
        RectF oval3 = new RectF(0, 0, width, height);// 设置个新的长方形
        canvas.drawRoundRect(oval3, DensityUtil.dp2px(radius), ResUtil.getSize(radius), paint);//第二个参数是x半径，第三个参数是y半径

        return bitmap;*/
        return getBitmap(getWidth(), getHeight());
    }
}
